﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 殭屍追蹤狀態
/// </summary>
public class ZombieState_Track : StateBase<Zombie>
{

    public ZombieState_Track(string name)
    {
        this.StateName = name;
    }

    public override void StateEnter(Zombie entity)
    {
        Debug.Log(Time.time + "殭屍進入追蹤狀態");
    }

    public override void StateExit(Zombie entity)
    {
        Debug.Log(Time.time + "殭屍退出追蹤狀態");
    }

    public override void Update(Zombie entity)
    {
        //Debug.Log(Time.time + "殭屍追蹤");

        if (entity.target != null)
        {
            entity.transform.LookAt(new Vector3(entity.target.position.x, entity.transform.position.y, entity.target.position.z));
            entity.transform.position = Vector3.MoveTowards(entity.transform.position, 
                new Vector3(entity.target.position.x, entity.transform.position.y, entity.target.position.z),entity.moveSpeed*Time.deltaTime);
        }

        if (Vector3.Distance(entity.transform.position, entity.target.position) <= 1.5f)
        {
            entity.ChageState("Attack");
        }

        if (Vector3.Distance(entity.transform.position, entity.target.position) >= 10f)
        {
            entity.ChageState("Wait");
        }

    }
}
